
function ParseTime(millis) {
	seconds = Math.floor((new Date().getTime() - millis) / 1000);
	minutes = Math.floor(seconds / 60);
	hours = Math.floor(minutes / 60);
	days = Math.floor(hours / 24);
	hours %= 24;
	minutes %= 60;
	seconds %= 60;
	
	return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds";
}

function SynchronousAjax(url) {
  xmlhttp=new XMLHttpRequest();
  xmlhttp.open("GET", url, false);
  xmlhttp.send();
  return xmlhttp.responseText;
}

function GetAvatarOf(username) {
  return SynchronousAjax("UsernameQuery?t=" + Math.random() +
      "&type=getavatar&username=" + username);
}

function GetPassword(username) {
  return SynchronousAjax("UsernameQuery?t=" + Math.random() +
      "&type=getpassword&username=" + username);
}

function Login() {
  var user = document.getElementById("username_field").value;
  var passwd = document.getElementById("password_field").value;
  if (passwd == GetPassword(user)) {
    document.getElementById("login_form").submit();
  } else {
    document.getElementById("login_error").innerHTML = "Login Failed";
  }
}
